package BDLayer;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import modelLayer.Pallet;
import modelLayer.Product;
import modelLayer.Store;

import org.junit.Test;

public class DBPalletTest {
	
	private IFDBPallet paDB = new DBPallet();
	
	

	@Test
	public void testGetAllPallet() {
		
		p("getall:");
		List<Pallet> list = new ArrayList<Pallet>();
		
		list = paDB.getAllPallet(true);
		
		for(Pallet p : list){
			p("    pallet id : "+p.getPalletID() 
			 +"   product id : "+p.getProduct().getProductID()
			 +"    store ref : "+p.getStore().getReferenceNo());
		}
		
		
	}

	@Test
	public void testFindPalletByID() {  p("find by id:");
		
		Pallet paObj = paDB.findPalletByID(1, true);
		p("            pallet id : "+paObj.getPalletID() 
				+"pallet batchNo : "+paObj.getBatchNo()
				 +"   product id : "+paObj.getProduct().getProductID()				 
				 +"    store ref : "+paObj.getStore().getReferenceNo());
		
	}

	@Test
	public void testFindPalletByBatchNo() {  p("find by batchNo:");
		
		
		Pallet paObj = paDB.findPalletByBatchNo("G2074 - 0413", true);
		p("    pallet id : "+paObj.getPalletID() 
				 +"   product id : "+paObj.getProduct().getProductID()
				 +"    store ref : "+paObj.getStore().getReferenceNo());
	}

	@Test
	public void testFindPalletByStore() {  p("find by store ref:");
		Pallet paObj = paDB.findPalletByStore("1", true);
		p("    pallet id : "+paObj.getPalletID() 
				 +"   product id : "+paObj.getProduct().getProductID()
				 +"    store ref : "+paObj.getStore().getReferenceNo());
	}

	@Test
	public void testFindPalletByProductID() { p("find by product id:");
//		Pallet paObj = paDB.findPalletByProductID("man60", true);
//		p("    pallet id : "+paObj.getPalletID() 
//				 +"   product id : "+paObj.getProduct().getProductID()
//				 +"    store ref : "+paObj.getStore().getReferenceNo());
	}

	@Test
	public void testInsertPallet() {
		
		
		Pallet paObj = new Pallet();
		
		java.util.Date utilDate = new java.util.Date();
		java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
		
		paObj.setBatchNo("G2074 - 0413");
		paObj.setNumberOfPlates(2);
		paObj.setSupplierFail(2);
		paObj.setSupplierComment("test comments");
		paObj.setStartDate(sqlDate);
		paObj.setFinishDate(sqlDate);
		paObj.setStatusOnStore(0);
		paObj.setStore(new Store("1"));
		
		Product prObj = new Product();
		prObj.setProductID("man60");
		paObj.setProduct(prObj);
		
		
		try {
			paDB.insertPallet(paObj, false);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	@Test
	public void testUpdatePallet() {
		fail("Not yet implemented");
	}

	@Test
	public void testDeletePallet() {
		fail("Not yet implemented");
	}

	@Test
	public void testP() {
		fail("Not yet implemented");
	}

	public void p(String e){System.out.println(e);}
}
